﻿using Furion.Schedule;

namespace Jobs;

/// <summary>
/// 定时任务 - 拼团加入机器人
/// </summary>
public class TeamJoinRobot : IJob
{
    private readonly ISqlSugarClient db;

    private readonly Logics.Teambuy teamLogic;

    public TeamJoinRobot(ISqlSugarClient db, Logics.Teambuy teamLogic)
    {
        this.db = db;
        this.teamLogic = teamLogic;
    }


    public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
    {
        var teams = await db.Queryable<Entity.TeamBuy>().Where(x => x.CurrentNum == 5 && x.State == Entity.TeamBuyState.进行中).ToListAsync();

        foreach (var team in teams) await teamLogic.AddRobot(team.Id);
    }
}
